﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Input;

namespace GameLib1
{
    class Button : GameObject
    {
        public enum ACTION
        {
            EXIT,
            LEVEL_SELECT,
            OPTIONS,
            MAP_EDITOR,
            CREDITS,
        }

        ACTION mAction;
        bool mClicked = false ;

        public Button(Vector2 pos, ACTION to_do) : base( pos, null )
        {
            mAction = to_do ;

            switch (mAction)
            {
                case ACTION.EXIT:
                    mTexture = TextureManager.current.texture("Button_Quit");
                    break;

                case ACTION.LEVEL_SELECT:
                    mTexture = TextureManager.current.texture("Button_Start");
                    break;

                case ACTION.OPTIONS:
                    mTexture = TextureManager.current.texture("Button_Options");
                    break;

                case ACTION.MAP_EDITOR:
                    mTexture = TextureManager.current.texture("Button_Level_Editor");
                    break;

                case ACTION.CREDITS:
                    mTexture = TextureManager.current.texture("Button_Quit");
                    break;

                default:
                    Console.Error.Write("Uh on hwo eowuaefn");
                    break;
            }

        }

        public override void Update(float dt) 
        {
            if (Mouse.GetState().LeftButton == ButtonState.Pressed)
            {
                Vector2 cam_rel = Camera.Position + mPos;
                if (Mouse.GetState().X > cam_rel.X && Mouse.GetState().Y > cam_rel.Y)
                {
                    if (Mouse.GetState().X < cam_rel.X + mTexture.Width && Mouse.GetState().Y < cam_rel.Y + mTexture.Height)
                    {
                        mClicked = true;
                    }
                }
            }

            if (mClicked)
            {
                switch (mAction)
                {
                    case ACTION.EXIT:
                        StateManager.current.mState = STATE.QUIT;
                        break;

                    case ACTION.LEVEL_SELECT:
                        break;

                    case ACTION.OPTIONS:
                        break;

                    case ACTION.MAP_EDITOR:
                        StateManager.current.mState = STATE.CHANGE;
                        StateManager.current.mLevel = LEVEL.MAP_EDITOR;
                        break;

                    case ACTION.CREDITS:
                        break;

                    default:
                        Console.Error.Write("Uh on hwo eowuaefn");
                        break;
                }
            }

            base.Update(dt);
        }

    }
}
